package com.example.ssmdemo0816.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @RequestMapping("/add_read")
    public int recordClick() {
        if(redisTemplate.opsForValue().get("click") == null) {
            redisTemplate.opsForValue().set("click", "1");
            return 1;
        } else {
            redisTemplate.opsForValue().increment("click");
            return 1;
        }
    }

}
